﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Http;
using Newtonsoft.Json;
using Water.Model;
using System.Net.Http.Headers;
using System.Collections.Generic;

namespace Water.Rest.UnitTest
{
    [TestClass]
    public class MeterReadingUnitTest
    {
        string basUrl = "http://localhost:46518/";//"http://180.169.20.194:8015/";//

        #region 抄表数据
        [TestMethod]
        public void GetMeterReadingsCount()
        {
            string url = basUrl + "GetMeterReadingsCount";
            var requestJson = JsonConvert.SerializeObject(new MeterReading { Memo = "aa" });
            HttpContent httpContent = new StringContent(requestJson);
            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }
        [TestMethod]
        public void GetMeterReadings()
        {
            string url = basUrl + "GetMeterReadings/1/2";
            MeterReading info = new MeterReading();
            //info.Mt = new Meter() { LOCATION = "哈哈" };
            var requestJson = JsonConvert.SerializeObject(info);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
            var mr = JsonConvert.DeserializeObject<IList<MeterReading>>(responseJson);
        }

        [TestMethod]
        public void AddMeterReading()
        {
            string url = basUrl + "AddMeterReading";
            MeterReading mr = new MeterReading { EpcNO = "AABBBBADD", CopyCode = 11, MeterDt = DateTime.Now, MeterEmp = "aaa", WaterCon = 33, Memo = "aa" };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(mr);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddUpdateWater()
        {
            string url = basUrl + "AddUpdateWater";
            UpdateWater uw = new UpdateWater
            {
                EpcNo = "AABBBBADD",
                UpdateDt = DateTime.Now,
                WaterName = "water001",
                WaterKJ = 35,
                WaterNo = "SB00001",
                Memo = "aa",
                UpdateEmp = "aaa"
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddBigValve()
        {
            string url = basUrl + "AddBigValve";
            BigValve uw = new BigValve
            {
                EpcNo = "AEEEFASDF",
                PipeNet = "正常",
                InspectionEmp = "aaa",
                InspectionDt = DateTime.Now,
                ProcessingQk = "巡检正常"
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddBigValvePileOfNo()
        {
            string url = basUrl + "AddBigValvePileOfNo";
            BigValvePileOfNo uw = new BigValvePileOfNo
            {
                EpcNo = "AEEEFASDF",
                InspectioZk = "巡检正常",
                InspectionEmp = "aaa",
                InspectionDt = Convert.ToDateTime("2013-06-28"),
                StartWorkDt = Convert.ToDateTime("2013-06-28"),
                FinishWorkDt = Convert.ToDateTime("2013-06-29"),
                Memo = "aa" 
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddFireHydrant()
        {
            string url = basUrl + "AddFireHydrant";
            FireHydrant uw = new FireHydrant
            {
                EpcNo = "AEEEFASDF",
                FireHydrantState = "巡检正常",
                InspectionEmp = "aaa", 
                InspectionDt = Convert.ToDateTime("2013-06-28"),
                ProcessQk = "正常" 
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddBridgePipeLedger()
        {
            string url = basUrl + "AddBridgePipeLedger";
            BridgePipeLedger uw = new BridgePipeLedger
            {
                EpcNo = "AEWQEWRQWER",
                ValveNull = "已放空阀门",
                Memo = "aa",
                OpertionEmp = "aaa" 
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddPipeNetDamageLedger()
        {
            string url = basUrl + "AddPipeNetDamageLedger";
            PipeNetDamageLedger uw = new PipeNetDamageLedger
            {
                EpcNo = "AEWQEWRQWER",
                DamageReason = "年久失修",
                FaultSource = "用户",
                FaultDt = Convert.ToDateTime("2013-06-25"),
                StartDt = Convert.ToDateTime("2013-06-25"),
                FinishDt = Convert.ToDateTime("2013-06-26"),
                FinishDept = "Dept1",
                OpertionEmp = "aaa" 
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddValveFaultRepair()
        {
            string url = basUrl + "AddValveFaultRepair";
            ValveFaultRepair uw = new ValveFaultRepair
            {
                EpcNo = "AEWQEWRQWER",
                MaintainDt = Convert.ToDateTime("2013-06-26"),
                Telphone = "13234321233",
                UseAddress = "xxx路1234号",
                Reason = "未知",
                Result = "已解决",
                ProcessEmp = "aaa", 
                InfoSource = "信" 
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddExplosionAccident()
        {
            string url = basUrl + "AddExplosionAccident";
            ExplosionAccident uw = new ExplosionAccident
            {
                EpcNo = "AEWQEWRQWER",
                ExplodeDt = Convert.ToDateTime("2013-07-04"),
                ExplodeAddress = "新村路89弄20号",
                OpertionEmp = "andy"   
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddPipeNetCheck()
        {
            string url = basUrl + "AddPipeNetCheck";
            PipeNetCheck uw = new PipeNetCheck
            {
                EpcNo = "EEWADFADSFAS",
                CheckDt = Convert.ToDateTime("2013-06-27"),
                CheckTime = "12:45:00",
                LoushuiQk = "有少量漏水",
                CheckEmp = "aaa"
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddFlushWaterAccount()
        {
            string url = basUrl + "AddFlushWaterAccount";
            FlushWaterAccount uw = new FlushWaterAccount
            {
                EpcNo = "EEWADFADSFAS",
                FlushDt = Convert.ToDateTime("2013-06-27"),
                FlushTimes = Convert.ToDouble("3"),
                FlushLen = Convert.ToDouble("4.5"),
                FlushLF = Convert.ToDouble("234.6"),
                FlushEmp = "aaa",
                Memo = "aa"  
  
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddBigValveOperate()
        {
            string url = basUrl + "AddBigValveOperate";
            BigValveOperate uw = new BigValveOperate
            {
                EpcNo = "AEEEFASDF",
                FillInDt = Convert.ToDateTime("2013-06-25"),
                CloseDt = Convert.ToDateTime("2013-06-25"),
                StartDt = Convert.ToDateTime("2013-06-26"),
                ZhuanCount = Convert.ToInt32("5"), 
                StartDirection = "北",
                OperateEmp = "aaa"     
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddSmallValveOperate()
        {
            string url = basUrl + "AddSmallValveOperate";
            SmallValveOperate uw = new SmallValveOperate
            {
                EpcNo = "EFADDADF",
                FillInDt = Convert.ToDateTime("2013-06-26"),
                CloseDt = Convert.ToDateTime("2013-06-26"),
                StartDt = Convert.ToDateTime("2013-06-27"),
                ZhuanCount = Convert.ToInt32("5"),
                StartDirection = "B方向",
                OperateEmp = "aaa"
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void AddPipeNetManometry()
        {
            string url = basUrl + "AddPipeNetManometry";
            PipeNetManometry uw = new PipeNetManometry
            {
                EpcNo = "EEWADFADSFAS",
                MeasureDt = Convert.ToDateTime("2013-06-27"),
                Times = Convert.ToDouble("5"),
                WaterPressure = Convert.ToDouble("256.4"),
                Style = "addd",
                JzWaterPressure = Convert.ToDouble("254.4"),
                OperateEmp = "aaa" 
            };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(uw);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void GetPassValidation()
        {
            string url = basUrl + "GetPassValidation/andy/123456";
            
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            //var requestJson = JsonConvert.SerializeObject(uw);
            //HttpContent httpContent = new StringContent(requestJson);

            //httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.GetAsync(url)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void GetDropdownlists()
        {
            string url = basUrl + "GetDropdownlists/1";
            
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            //var requestJson = JsonConvert.SerializeObject(uw);
            //HttpContent httpContent = new StringContent(requestJson);

            //httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.GetAsync(url)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void lnksave_Click()
        {
            string url = basUrl + "AddTagAndDevice";
            Water.Model.TagInitialize ti = new Water.Model.TagInitialize()
            {
                DeviceType = "2",
                DeviceNo = "W00001",
                TagNo = "AEQERQWERQWERQWER"
            };

            var requestJson = JsonConvert.SerializeObject(ti);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;

        }


        /*===================================================================================*/
        [TestMethod]
        public void EditMeterReading()
        {
            string url = basUrl + "GetMeterReading/20130621001";
            var httpClient = new HttpClient();
            var response = httpClient.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
            var mr = JsonConvert.DeserializeObject<MeterReading>(response);

            url = basUrl + "EditMeterReading";
            var requestJson = JsonConvert.SerializeObject(new MeterReading { MRNO = "20130621001",EpcNO="01", CopyCode = 12, MeterDt = DateTime.Now, MeterEmp = "11", WaterCon = 33, Memo = "bb" });
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

           // var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void DeleteMeterReading()
        {
            string url = basUrl + "DeleteMeterReading/20130621002";
            var httpClient = new HttpClient();
            var response = httpClient.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void GetMeterReading()
        {
            string url = basUrl + "GetMeterReading/20130621001";
            var httpClient = new HttpClient();
            var response = httpClient.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
            var mr = JsonConvert.DeserializeObject<MeterReading>(response);
        }

        #endregion
    }
}
